var fak = function(x) {
    var f = 1;
    for (var i = 2; i <= x; i++) {
        f = f*i;
    }
    return f;
};

var rand = function() {
	return Math.round( 10000000 * Math.random() );
};

var MAX_ITERS = 10000000;

var test = function() {
    var result = 0;
    
    for (var i = MAX_ITERS; i > 0; --i)
        result = (fak(1 + Math.round(10 * Math.random())) + result) % 1000;

    alert("result = " + result);
    return 0;
}

var t0 = +new Date;
test();
var t1 = +new Date;
alert("time = " + (t1 - t0) + " ms.");
